package com.ruimei.controller;


import com.alibaba.fastjson.JSONArray;
import com.ruimei.entitys.LeaveTeacher;
import com.ruimei.entitys.Teacher;
import com.ruimei.service.TeacherLeaveService;
import com.ruimei.util.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags={"教师请假"})
@Controller
public class TeacherLeaveController {
    @Resource
    TeacherLeaveService service;
    @Resource
    private RedisTemplate<String,String> redisTemplate;

    @PostMapping({"/getdept"})
    @ResponseBody
    @ApiOperation("获取部门")
    public Map<String, Object> getDept()
    {
        Map<String, Object> map = service.getDept();
        return map;
    }

    @PostMapping({"/getteacher"})
    @ResponseBody
    @ApiOperation("通过部门获取教师")
    public Map<String, Object> getTeacher(String deptId)
    {
        Map<String, Object> map = service.getTeacher(deptId);
        return map;
    }

    @PostMapping({"/teacherleave/add"})
    @ResponseBody
    @ApiOperation("请假申请")
    public Map<String, Object> addTeacherLeave(LeaveTeacher leaveTeacher, HttpServletRequest request)
    {
        Teacher teacher = new Teacher();
        teacher.setId(TokenUtils.getTeacherId(request));
        if(redisTemplate.hasKey(teacher.getId())) {
            leaveTeacher.setTeacherId(teacher.getId());
            Map<String, Object> map = service.addTeacherLeave(leaveTeacher);
            return map;
        }
        return null;
    }

    @PostMapping({"/teacherleave"})
    @ResponseBody
    @ApiOperation("获取教师请假")
    public Map<String, Object> getTeacherLeave(LeaveTeacher leaveTeacher)
    {
        Map<String, Object> map = service.getTeacherLeave(leaveTeacher);
        return map;
    }

    @PostMapping({"/teacherleave/set"})
    @ResponseBody
    @ApiOperation("修改教师请假")
    public Map<String, Object> setTeacherLeave(LeaveTeacher leaveTeacher)
    {
        Map<String, Object> map = service.setTeacherLeave(leaveTeacher);
        return map;
    }


}
